/*
 * TextComponentClearAction.java  0.4.0 / Oct 23, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
package com.cute4j.swingx.actions;

import com.cute4j.swing.TextComponent;
import com.cute4j.swing.events.ActionEvent;
import com.cute4j.swing.events.EditListener;

/**
 * Text Component Clear Action.
 *
 * @author Slobodan Vrkacevic
 * @version 0.4.0
 */
public class TextComponentClearAction extends ClearAction
                                      implements EditListener {

// Protected Fields. -----------------------------------------------------------

  protected final TextComponent textComponent;

// Public Constructors. --------------------------------------------------------

  /**
   * Constructs new TextComponentClearAction object.
   *
   * @param textComponent the text component
   */
  public TextComponentClearAction(TextComponent textComponent) {
    if (textComponent == null) {
      throw new IllegalArgumentException("Null text component");
    }
    this.textComponent = textComponent;
    textComponent.addEditListener(this);
    setEnabled(textComponent.isClearAvailable());
  }

// Public Methods. -------------------------------------------------------------

  /**
   * Unregisters listener.
   */
  public void unregisterListener() {
    textComponent.removeEditListener(this);
  }

// Overridden Methods. ---------------------------------------------------------

  /**
   * {@inheritDoc}
   */
  public void actionPerformed(ActionEvent e) {
    if (isEnabled()) {
      textComponent.clear();
    }
  }

  /**
   * {@inheritDoc}
   */
  public void cutAvailable(boolean available) {
    // empty method
  }

  /**
   * {@inheritDoc}
   */
  public void copyAvailable(boolean available) {
    // empty method
  }

  /**
   * {@inheritDoc}
   */
  public void pasteAvailable(boolean available) {
    // empty method
  }

  /**
   * {@inheritDoc}
   */
  public void clearAvailable(boolean available) {
    setEnabled(available);
  }

  /**
   * {@inheritDoc}
   */
  public void selectAllAvailable(boolean available) {
    // empty method
  }

}
